﻿using RecruitStudents.Utility.Json;
using RecruitStudents.Utility.Model;
using RecruitStudents.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hxj.Data;
using RecruitStudents.Utility.Helper;
using System.Data;

namespace RecruitStudents.Client.BLL.Impl
{
    public class BLLBase
    {
        DAL.DALBase dal = new DAL.DALBase();
        #region 数据字典维护
        public DataTable GetDicMain()
        {
            return dal.GetTable("select * from TB_Dic_Main order by Sort");
        }

        public DataTable GetDicValueByTableName(string strTableName, string strIsActive)
        {
            if (strTableName.IsNullOrEmptyString())
            {
                return null;
            }
            string strWhere = string.Empty;
            if (!strIsActive.IsNullOrEmptyString())
            {
                strWhere = "where IsActive='" + strIsActive.RemoveSqlInjection() + "'";
            }
            return dal.GetTable("select * from " + strTableName.RemoveSqlInjection() + " " + strWhere);
        }
        public DataTable GetDicValue(string strTableName, string strDicNo)
        {
            if (strTableName.IsNullOrEmptyString())
            {
                return null;
            }
            string strSql = string.Format("select * from {0} where DicNO='{1}'", strTableName.RemoveSqlInjection(), strDicNo.RemoveSqlInjection());
            return dal.GetTable(strSql);
        }

        public JsonMessage SaveDicValue(string strTableName, string DicNO, string DicName, string IsActive)
        {
            JsonMessage message = new JsonMessage();
            if (strTableName.IsNullOrEmptyString() || DicName.IsNullOrEmptyString())
            {
                message.State = "false";
                message.Msg = "操作失败:参数值不能为空";
                return message;
            }
            try
            {
                strTableName = strTableName.RemoveSqlInjection();
                DicNO = DicNO.RemoveSqlInjection();
                DicName = DicName.RemoveSqlInjection();
                if (string.IsNullOrEmpty(DicNO))
                {
                    dal.ExecuteNonQuery("insert into " + strTableName + " select ISNULL(MAX(DicNo),0)+1,'" + DicName + "','" + IsActive + "' from " + strTableName + "");
                }
                else
                {
                    DataTable dt = DbHelper.GetDatabase().FromSql("select * from " + strTableName + " where DicNO='" + DicNO + "'").ToDataTable();
                    if (dt.Rows.Count > 0)
                    {
                        dal.ExecuteNonQuery(string.Format("update {0} set DicName='{1}',IsActive='" + IsActive + "' where DicNO='{2}'", strTableName, DicName, DicNO));
                    }
                    else
                    {
                        dal.ExecuteNonQuery(string.Format("insert into {0} values ('{1}','{2}','{3}')", strTableName, DicNO, DicName, IsActive));
                    }
                }
                message.State = "true";
                message.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "操作失败:" + ex.Message;
            }
            return message;
        }

        #endregion

        #region Mac管理
        public DataTable GetExamMacByRoomTable(string strKSND)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strKSND))
            {
                wcp = wcp.And(TB_Exam_Mac._.ExamYear == strKSND);
            }
            wcp = wcp.And(TB_Exam_Mac._.IsActive == "1");
            return dal.GetExamMacByRoomTable(wcp);
        }
        public DataTable GetExamMacTable(string strKSND, string strKC, string strSFTY, string strMacName)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strKSND))
            {
                wcp = wcp.And(TB_Exam_Mac._.ExamYear == (strKSND));
            }
            if (!string.IsNullOrEmpty(strSFTY))
            {
                wcp = wcp.And(TB_Exam_Mac._.IsActive == strSFTY);
            }
            if (!string.IsNullOrEmpty(strMacName))
            {
                wcp = wcp.And(TB_Exam_Mac._.MachineName.Contain(strMacName));
            }
            return dal.GetExamMacTable(wcp);
        }

        public TB_Exam_Mac GetExamMacModel(string strWhere)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Exam_Mac._.MacID == strWhere);
            return dal.GetModel<TB_Exam_Mac>(wcp);
        }
        public JsonMessage SaveExamMac(string strJson)
        {
            JsonMessage json = null;
            if (strJson.IsNullOrEmptyString())
            {
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:参数Json为空，无法转换";
            }
            else
            {
                try
                {
                    TB_Exam_Mac model = strJson.ToList<TB_Exam_Mac>();
                    if (model != null)
                    {
                        if (model.IsNewModel)
                        {
                            model.MachineName = dal.ToScalar<string>(" select ISNULL(substring(max(cast(1000 + cast(MachineName as int) + 1 as nvarchar(4))),2,3),'001') as MachineName from TB_Exam_Mac ");
                        }
                    }
                    dal.Save<TB_Exam_Mac>(model);
                    json = new JsonMessage();
                    json.State = "true";
                    json.Msg = "操作成功";
                }
                catch (Exception ex)
                {
                    json = new JsonMessage();
                    json.State = "false";
                    json.Msg = "操作失败:" + ex.Message;
                }
            }
            return json;
        }
        #endregion

        #region 用户管理
        public DataTable GetUserTable(string strLoginName, string strName, string strType)
        {
            WhereClip wcp = new WhereClip();
            if (strType.Length > 0)
            {
                wcp = wcp.And(TB_Sys_User._.Type == strType);
            }
            if (strLoginName.Length > 0)
            {
                wcp = wcp.And(TB_Sys_User._.LoginName.Contain(strLoginName));
            }
            if (strName.Length > 0)
            {
                wcp = wcp.And(TB_Sys_User._.Name.Contain(strName));
            }
            return dal.GetUserTable(wcp);
        }

        public TB_Sys_User GetUserModel(string strID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_User._.UserID == strID);
            return dal.GetModel<TB_Sys_User>(wcp);
        }

        public JsonMessage SaveUser(string strJson)
        {
            JsonMessage json = null;
            if (strJson.IsNullOrEmptyString())
            {
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:参数Json为空，无法转换";
            }
            else
            {
                try
                {
                    TB_Sys_User model = strJson.ToList<TB_Sys_User>();
                    dal.Save<TB_Sys_User>(model);
                    json = new JsonMessage();
                    json.State = "true";
                    json.Msg = "操作成功";
                }
                catch (Exception ex)
                {
                    json = new JsonMessage();
                    json.State = "false";
                    json.Msg = "操作失败:" + ex.Message;
                }
            }
            return json;
        }

        public JsonMessage DeleteUser(string strID)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Sys_User>(TB_Sys_User._.UserID == strID);
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }
        #endregion

        #region 角色管理
        public DataTable GetRoleTable(string strRoleName, string strIsActive)
        {
            WhereClip wcp = new WhereClip();
            if (strRoleName.Length > 0)
            {
                wcp = wcp.And(TB_Sys_Role._.RoleName.Contain(strRoleName));
            }
            if (strIsActive.Length > 0)
            {
                wcp = wcp.And(TB_Sys_Role._.IsActive == strIsActive);
            }
            return dal.GetTable<TB_Sys_Role>(wcp, new OrderByClip(TB_Sys_Role._.CreateDate, OrderByOperater.DESC));
        }

        public TB_Sys_Role GetRoleModel(string strID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_Role._.RoleID == strID);
            return dal.GetModel<TB_Sys_Role>(wcp);
        }

        public JsonMessage SaveRole(string strJson)
        {
            JsonMessage json = null;
            if (strJson.IsNullOrEmptyString())
            {
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:参数Json为空，无法转换";
            }
            else
            {
                DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
                try
                {
                    TB_Sys_Role model = strJson.ToList<TB_Sys_Role>();
                    dal.Save<TB_Sys_Role>(model, trans);
                    trans.Commit();
                    json = new JsonMessage();
                    json.State = "true";
                    json.Msg = "操作成功";
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    json = new JsonMessage();
                    json.State = "false";
                    json.Msg = "操作失败:" + ex.Message;
                }
                finally
                {
                    trans.Close();
                }
            }
            return json;
        }

        public JsonMessage DeleteRole(string strID)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                dal.Delete<TB_Sys_Role>(TB_Sys_Role._.RoleID == strID, trans);
                dal.Delete<TB_Sys_RoleAuth>(TB_Sys_RoleAuth._.RoleID == strID, trans);
                message.State = "true";
                message.Msg = "删除成功!";
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public DataTable GetModuleTable()
        {
            WhereClip wcp = new WhereClip();
            return dal.GetTable<TB_Sys_Module>(wcp, new OrderByClip(TB_Sys_Module._.Sort, OrderByOperater.ASC));
        }

        public JsonMessage SaveRoleAuth(string strJson)
        {
            JsonMessage message = new JsonMessage();
            List<TB_Sys_RoleAuth> list = strJson.ToList<List<TB_Sys_RoleAuth>>();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                if (list != null && list.Count > 0)
                {
                    DbHelper.GetDatabase().FromSql("delete TB_Sys_RoleAuth where RoleID='" + list[0].RoleID + "'").SetDbTransaction(trans).ExecuteNonQuery();
                    foreach (TB_Sys_RoleAuth model in list)
                    {
                        dal.Save<TB_Sys_RoleAuth>(model, trans);
                    }
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public DataTable GetRoleAuthModuleTable(string strRoleID)
        {
            return dal.GetRoleAuthModuleTable(strRoleID);
        }
        #endregion

        #region 考官管理
        public DataTable GetExaminerTableByDropDown(string strYear, string strRoomID, string strSpec)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Exam_Examiner._.IsActive == "1");
            if (!string.IsNullOrEmpty(strYear))
            {
                wcp = wcp.And(TB_Exam_Examiner._.ExamYear == strYear);
            }
            if (!string.IsNullOrEmpty(strSpec))
            {
                wcp = wcp.And(TB_Exam_Examiner._.SpecialityKindsNO == strSpec);
            }
            if (!string.IsNullOrEmpty(strRoomID))
            {
                wcp = wcp.And("ExaminerID not in (select ExaminerID from TB_Exam_ExamRoomExaminerMapping where ExamRoomNO='" + strRoomID + "')");
            }
            return dal.GetExaminerTable(wcp);
        }

        public DataTable GetExaminerTable(string strLoginName, string strName, string strType, string strSSZY, string strYear)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strType))
            {
                wcp = wcp.And(TB_Exam_Examiner._.SpecialityKinds_DetailNO == strType);
            }
            if (!string.IsNullOrEmpty(strSSZY))
            {
                wcp = wcp.And(TB_Exam_Examiner._.SpecialityKindsNO == strSSZY);
            }
            if (!string.IsNullOrEmpty(strYear))
            {
                wcp = wcp.And(TB_Exam_Examiner._.ExamYear == strYear);
            }
            if (!string.IsNullOrEmpty(strLoginName))
            {
                wcp = wcp.And(TB_Exam_Examiner._.LoginName.Contain(strLoginName));
            }
            if (!string.IsNullOrEmpty(strName))
            {
                wcp = wcp.And(TB_Exam_Examiner._.ExaminerName.Contain(strName));
            }
            return dal.GetExaminerTable(wcp);
        }

        public TB_Exam_Examiner GetExaminerModel(string strExaminerID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Exam_Examiner._.ExaminerID == strExaminerID);
            return dal.GetModel<TB_Exam_Examiner>(wcp);
        }

        public JsonMessage SaveExaminer(string strJson)
        {
            JsonMessage json = null;
            try
            {
                TB_Exam_Examiner model = strJson.ToList<TB_Exam_Examiner>();
                if (model.IsNewModel)
                {
                    if (dal.GetModel<TB_Exam_Examiner>(TB_Exam_Examiner._.LoginName == model.LoginName) != null)
                    {
                        json = new JsonMessage();
                        json.State = "false";
                        json.Msg = "操作失败:考官登录名已经存在,请重新输入";
                        return json;
                    }
                }
                dal.Save<TB_Exam_Examiner>(model);
                json = new JsonMessage();
                json.State = "true";
                json.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:" + ex.Message;
            }
            return json;
        }
        #endregion

        #region 考官考场关联
        public DataTable GetExaminerRoomDataTable(string strExamRoomNO, string strExaminerID, string strExamYear)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Exam_ExamRoomExaminerMapping._.IsActive == "1");
            if (!string.IsNullOrEmpty(strExamRoomNO))
            {
                wcp = wcp.And(TB_Exam_ExamRoomExaminerMapping._.ExamRoomNO == strExamRoomNO);
            }
            if (!string.IsNullOrEmpty(strExaminerID))
            {
                wcp = wcp.And(TB_Exam_ExamRoomExaminerMapping._.ExaminerID == strExaminerID);
            }
            if (!string.IsNullOrEmpty(strExamYear))
            {
                wcp = wcp.And(TB_Exam_ExamRoomExaminerMapping._.ExamYear == strExamYear);
            }
            return dal.GetExaminerRoomDataTable(wcp);
        }

        public JsonMessage DeleteExaminerRoomMapping(string strExamRoomNO, string strExaminerID, string strExamYear)
        {
            JsonMessage json = null;
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                string strSql = "delete TB_Exam_ExamRoomExaminerMapping where ExamRoomNO='" + strExamRoomNO + "' and ExaminerID='" + strExaminerID + "' and ExamYear='" + strExamYear + "'";
                dal.ExecuteNonQuery(strSql);
                trans.Commit();
                json = new JsonMessage();
                json.State = "true";
                json.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:" + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return json;
        }

        public JsonMessage SaveExaminerRoomMapping(string strJson)
        {
            JsonMessage json = null;
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                List<TB_Exam_ExamRoomExaminerMapping> list = strJson.ToList<List<TB_Exam_ExamRoomExaminerMapping>>();
                foreach (TB_Exam_ExamRoomExaminerMapping model in list)
                {
                    dal.Save<TB_Exam_ExamRoomExaminerMapping>(model, trans);
                }
                trans.Commit();
                json = new JsonMessage();
                json.State = "true";
                json.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:" + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return json;
        }
        #endregion

        #region 专业相关
        public TB_Sys_SpecialityKinds GetSpecialityKindsModel(string strSpecialityKindsNO)
        {
            return dal.GetModel<TB_Sys_SpecialityKinds>(TB_Sys_SpecialityKinds._.SpecialityKindsNO == strSpecialityKindsNO);
        }

        public DataTable GetSpecialityKindsDataTable(string strYear, string strSpecialityKindsNO, string strSpecialityKindsName, string strIsActive, string strIsSchool)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(strYear))
            {
                clip = clip.And(TB_Sys_SpecialityKinds._.ExamYear == strYear);
            }
            if (!string.IsNullOrEmpty(strIsActive))
            {
                clip = clip.And(TB_Sys_SpecialityKinds._.IsActive == strIsActive);
            }
            if (!string.IsNullOrEmpty(strIsSchool))
            {
                clip = clip.And(TB_Sys_SpecialityKinds._.IsSchool == strIsSchool);
            }
            if (!string.IsNullOrEmpty(strSpecialityKindsNO))
            {
                clip = clip.And(TB_Sys_SpecialityKinds._.SpecialityKindsNO.Contain(strSpecialityKindsNO));
            }
            if (!string.IsNullOrEmpty(strSpecialityKindsName))
            {
                clip = clip.And(TB_Sys_SpecialityKinds._.SpecialityKindsName.Contain(strSpecialityKindsName));
            }
            return dal.GetTable<TB_Sys_SpecialityKinds>(clip);
        }

        public DataTable GetSpecialityKindsDetailTable(string strSpecialityKindsNO)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_SpecialityKinds_Detail._.IsActive == "1");
            if (!strSpecialityKindsNO.IsNullOrEmptyString())
            {
                wcp = wcp.And(TB_Sys_SpecialityKinds_Detail._.SpecialityKindsNO == strSpecialityKindsNO);
            }
            return dal.GetTable<TB_Sys_SpecialityKinds_Detail>(wcp);
        }

        public JsonMessage SaveSpecialityKinds(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_SpecialityKinds model = strJson.ToList<TB_Sys_SpecialityKinds>();
                if (model.IsNewModel)
                {
                    TB_Sys_SpecialityKinds mdl = dal.GetModel<TB_Sys_SpecialityKinds>(TB_Sys_SpecialityKinds._.SpecialityKindsNO == model.SpecialityKindsNO);
                    if (mdl != null)
                    {
                        message.State = "false";
                        message.Msg = "专业编码已经存在!";
                        return message;
                    }
                }
                if (model.Sort.ToSafeInt() == 0)
                {
                    model.Sort = dal.ToScalar<int>("select ISNULL(max(Sort),0)+1 from TB_Sys_SpecialityKinds");
                }
                dal.Save<TB_Sys_SpecialityKinds>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage SaveSpecialityKinds_Detail(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_SpecialityKinds_Detail model = strJson.ToList<TB_Sys_SpecialityKinds_Detail>();
                if (model.IsNewModel)
                {
                    model.SpecialityKinds_DetailNO = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                }
                //判断当前编码是否存在
                TB_Sys_SpecialityKinds_Detail mdl = dal.GetModel<TB_Sys_SpecialityKinds_Detail>(TB_Sys_SpecialityKinds_Detail._.SpecialityKinds_DetailNO == model.SpecialityKinds_DetailNO);
                if (mdl != null && model.IsNewModel == true)
                {
                    message.State = "false";
                    message.Msg = "细分专业编码已经存在!";
                }
                else
                {
                    dal.Save<TB_Sys_SpecialityKinds_Detail>(model);
                    message.State = "true";
                    message.Msg = "保存成功!";
                }
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public DataTable GetSpecialityKinds_DetailDataTable(string SpecialityKindsNO, string IsActive)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(IsActive))
            {
                clip = clip.And(TB_Sys_SpecialityKinds_Detail._.IsActive == IsActive);
            }
            if (!string.IsNullOrEmpty(SpecialityKindsNO))
            {
                clip = clip.And(TB_Sys_SpecialityKinds_Detail._.SpecialityKindsNO == SpecialityKindsNO);
            }
            return dal.GetTable<TB_Sys_SpecialityKinds_Detail>(clip);
        }

        public JsonMessage DeleteSpecialityKinds_Detail(string SpecialityKindsNo, string SpecialityKindsNo_Detail)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                DbHelper.GetDatabase().FromSql("delete TB_Sys_SpecialityKinds_Detail where SpecialityKindsNO='" + SpecialityKindsNo + "' and SpecialityKinds_DetailNO='" + SpecialityKindsNo_Detail + "'").SetDbTransaction(trans).ExecuteNonQuery();
                trans.Commit();
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "删除失败," + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage SaveSpecialityKinds_Detail_Sub(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_SpecialityKinds_Detail_Sub model = strJson.ToList<TB_Sys_SpecialityKinds_Detail_Sub>();
                if (model.IsNewModel)
                {
                    model.SpecialityKinds_Detail_SubNO = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                }
                //判断当前编码是否存在
                TB_Sys_SpecialityKinds_Detail_Sub mdl = dal.GetModel<TB_Sys_SpecialityKinds_Detail_Sub>(TB_Sys_SpecialityKinds_Detail_Sub._.SpecialityKinds_Detail_SubNO == model.SpecialityKinds_Detail_SubNO);
                if (mdl != null && model.IsNewModel == true)
                {
                    message.State = "false";
                    message.Msg = "细分专业编码已经存在!";
                }
                else
                {
                    dal.Save<TB_Sys_SpecialityKinds_Detail_Sub>(model);
                    message.State = "true";
                    message.Msg = "保存成功!";
                }
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public DataTable GetSpecialityKinds_Detail_SubDataTable(string SpecialityKindsDetailNO, string IsActive)
        {
            WhereClip clip = new WhereClip();
            if (!string.IsNullOrEmpty(IsActive))
            {
                clip = clip.And(TB_Sys_SpecialityKinds_Detail_Sub._.IsActive == IsActive);
            }
            if (!string.IsNullOrEmpty(SpecialityKindsDetailNO))
            {
                clip = clip.And(TB_Sys_SpecialityKinds_Detail_Sub._.SpecialityKinds_DetailNO == SpecialityKindsDetailNO);
            }
            return dal.GetTable<TB_Sys_SpecialityKinds_Detail_Sub>(clip);
        }

        public JsonMessage DeleteSpecialityKinds_Detail_Sub(string SpecialityKindsNo_Detail, string SpecialityKindsNo_Detail_Sub)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                DbHelper.GetDatabase().FromSql("delete TB_Sys_SpecialityKinds_Detail_Sub where SpecialityKinds_DetailNO='" + SpecialityKindsNo_Detail + "' and SpecialityKinds_Detail_SubNO='" + SpecialityKindsNo_Detail_Sub + "'").SetDbTransaction(trans).ExecuteNonQuery();
                trans.Commit();
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "删除失败," + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }
        /// <summary>
        /// 获取报考的考生类型
        /// </summary>
        /// <returns></returns>
        public DataTable GetSignUpStudentsType()
        {
            return dal.GetTable("select distinct b.SpecialityKinds_DetailNO, b.SpecialityKinds_DetailName from TB_Sys_SpecialityKinds_Detail_Sub a left join dbo.TB_Sys_SpecialityKinds_Detail b on a.SpecialityKinds_DetailNO = b.SpecialityKinds_DetailNO");
        }
        #endregion

        #region 考生号相关
        public DataTable GetDicNMTSignUpTable(string strName)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strName))
            {
                wcp = wcp.And(TB_Dic_NMT_SignUp._.NativePlaceName.Contain(strName));
            }
            return dal.GetTable<TB_Dic_NMT_SignUp>(wcp, new OrderByClip(TB_Dic_NMT_SignUp._.NativePlaceNO, OrderByOperater.ASC));
        }

        public TB_Dic_NMT_SignUp GetDicNMTSignUpModel(string strNativePlaceNO)
        {
            return dal.GetModel<TB_Dic_NMT_SignUp>(TB_Dic_NMT_SignUp._.NativePlaceNO == strNativePlaceNO);
        }

        public JsonMessage SaveDicNMTSignUp(string strJson)
        {
            JsonMessage json = null;
            if (strJson.IsNullOrEmptyString())
            {
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:参数Json为空，无法转换";
            }
            else
            {
                try
                {
                    TB_Dic_NMT_SignUp model = strJson.ToList<TB_Dic_NMT_SignUp>();
                    if (model == null)
                    {
                        json = new JsonMessage();
                        json.State = "false";
                        json.Msg = "操作失败:转换实体对象出现错误";
                    }
                    else
                    {
                        dal.Save<TB_Dic_NMT_SignUp>(model);
                        json = new JsonMessage();
                        json.State = "true";
                        json.Msg = "操作成功";
                    }
                }
                catch (Exception ex)
                {
                    json = new JsonMessage();
                    json.State = "false";
                    json.Msg = "操作失败:" + ex.Message;
                }
            }
            return json;
        }
        #endregion

        #region 考点相关
        public JsonMessage SaveSysExamPlaceLimit(string strJson)
        {
            JsonMessage message = new JsonMessage();
            List<TB_Sys_ExamPlace_Limit> list = strJson.ToList<List<TB_Sys_ExamPlace_Limit>>();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                if (list != null && list.Count > 0)
                {
                    DbHelper.GetDatabase().FromSql("delete TB_Sys_ExamPlace_Limit where ExamPlaceNO='" + list[0].ExamPlaceNO + "'").SetDbTransaction(trans).ExecuteNonQuery();
                    if (!string.IsNullOrEmpty(list[0].ExamProvince))
                    {
                        foreach (TB_Sys_ExamPlace_Limit model in list)
                        {
                            dal.Save<TB_Sys_ExamPlace_Limit>(model, trans);
                        }
                    }
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }
        public JsonMessage SaveSysExamPlace(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_ExamPlace model = strJson.ToList<TB_Sys_ExamPlace>();
                if (model == null)
                {
                    message.State = "false";
                    message.Msg = "操作失败:转换实体对象出现错误";
                }
                //判断当前编码是否存在
                TB_Sys_ExamPlace mdl = this.GetSysExamPlaceModel(model.ExamPlaceNO);
                if (mdl != null && model.IsNewModel == true)
                {
                    message.State = "false";
                    message.Msg = "考点编号已经存在!";
                    return message;
                }
                dal.Save<TB_Sys_ExamPlace>(model);
                message.State = "true";
                message.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "操作失败:" + ex.Message;
            }
            return message;
        }

        public DataTable GetSysExamPlaceDataTable(string strExamProvince, string strExamPlaceName, string strIsActive)
        {
            WhereClip clip = new WhereClip();
            if (strIsActive.Length > 0)
            {
                clip = clip.And(TB_Sys_ExamPlace._.IsActive == strIsActive);
            }
            if (strExamProvince.Length > 0)
            {
                clip = clip.And(TB_Sys_ExamPlace._.ExamProvince == strExamProvince);
            }
            if (strExamPlaceName.Length > 0)
            {
                clip = clip.And(TB_Sys_ExamPlace._.ExamPlaceName.Contain(strExamPlaceName));
            }
            return dal.GetSysExamPlaceDataTable(clip);
        }

        public DataTable GetSysExamPlace_Limit(string strExamPlaceNO)
        {
            return dal.GetTable("select * from TB_Sys_ExamPlace_Limit where ExamPlaceNO='" + strExamPlaceNO.RemoveSqlInjection() + "'");
        }

        public TB_Sys_ExamPlace GetSysExamPlaceModel(string strExamPlaceNO)
        {
            return dal.GetModel<TB_Sys_ExamPlace>(TB_Sys_ExamPlace._.ExamPlaceNO == strExamPlaceNO);
        }

        public JsonMessage DeleteSysExamPlace(string strExamPlaceNO)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Sys_ExamPlace>(TB_Sys_ExamPlace._.ExamPlaceNO == strExamPlaceNO);
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败," + ex.Message;
            }
            return message;
        }
        #endregion

        #region 算分规则
        public DataTable GetExamCalculateTypeFormTable(string strExamYear)
        {
            WhereClip wcp = new WhereClip();
            if (strExamYear.Length > 0)
            {
                wcp = wcp.And(TB_Rule_CalculateScore._.ExamYear == strExamYear);
            }
            return dal.GetTable<TB_Rule_CalculateScore>(wcp);
        }

        public TB_Rule_CalculateScore GetExamCalculateTypeFormModel(string strCalculateScoreID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Rule_CalculateScore._.CalculateScoreID == strCalculateScoreID);
            return dal.GetModel<TB_Rule_CalculateScore>(wcp);
        }

        public JsonMessage SaveExamCalculateTypeForm(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Rule_CalculateScore model = strJson.ToList<TB_Rule_CalculateScore>();
                if (model.IsNewModel)
                {
                    model.CalculateScoreNo = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                }
                dal.Save<TB_Rule_CalculateScore>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage DeleteExamCalculateTypeForm(string strCalculateScoreID)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Rule_CalculateScore>(TB_Rule_CalculateScore._.CalculateScoreID == strCalculateScoreID);
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }

        public DataTable GetExamCalculateTypeFormTable_Detail(string strCalculateScoreID)
        {
            WhereClip wcp = new WhereClip();
            if (strCalculateScoreID.Length > 0)
            {
                wcp = wcp.And(TB_Rule_CalculateScoreDetail._.CalculateScoreID == strCalculateScoreID);
            }
            return dal.GetExamCalculateTypeFormTable_Detail(wcp);
        }

        public TB_Rule_CalculateScoreDetail GetExamCalculateTypeFormModel_Detail(string strCalculateScoreDetailID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Rule_CalculateScoreDetail._.CalculateScoreDetailID == strCalculateScoreDetailID);
            return dal.GetModel<TB_Rule_CalculateScoreDetail>(wcp);
        }

        public JsonMessage SaveExamCalculateTypeForm_Detail(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Rule_CalculateScoreDetail model = strJson.ToList<TB_Rule_CalculateScoreDetail>();
                dal.Save<TB_Rule_CalculateScoreDetail>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage DeleteExamCalculateTypeForm_Detail(string strID)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Rule_CalculateScoreDetail>(TB_Rule_CalculateScoreDetail._.CalculateScoreDetailID == strID);
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }
        #endregion

        #region 考场相关
        public DataTable GetExamEntretenimientohRoomTable()
        {
            return dal.GetExamEntretenimientohRoomTable();
        }

        public DataTable GetRoomMacDataTable(string strRoomMacExamRoomNO, string strRoomMacNO, string strRoomMacExamYear)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strRoomMacExamYear))
            {
                wcp = wcp.And(TB_Exam_ExamRoomMacMapping._.ExamYear == strRoomMacExamYear);
            }
            if (!string.IsNullOrEmpty(strRoomMacExamRoomNO))
            {
                wcp = wcp.And(TB_Exam_ExamRoomMacMapping._.ExamRoomNO == strRoomMacExamRoomNO);
            }
            if (!string.IsNullOrEmpty(strRoomMacNO))
            {
                wcp = wcp.And(TB_Exam_ExamRoomMacMapping._.MacNo == strRoomMacNO);
            }
            return dal.GetRoomMacDataTable(wcp);
        }

        public DataTable GetExamEntretenimientohTable(string strYear, string strExamPlaceID, string strSpecialityKindsNO, string strExamLevel)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strYear))
            {
                wcp = wcp.And(TB_Exam_Entretenimientoh._.ExamYear == strYear);
            }
            if (!string.IsNullOrEmpty(strExamPlaceID))
            {
                wcp = wcp.And(TB_Exam_Entretenimientoh._.ExamPlaceNO == strExamPlaceID);
            }
            if (!string.IsNullOrEmpty(strSpecialityKindsNO))
            {
                wcp = wcp.And(TB_Exam_Entretenimientoh._.SpecialityKindsNO == strSpecialityKindsNO);
            }
            if (!string.IsNullOrEmpty(strExamLevel))
            {
                wcp = wcp.And(TB_Exam_Entretenimientoh._.ExamLevel == strExamLevel);
            }
            return dal.GetExamEntretenimientohTable(wcp);
        }

        public DataTable GetExamRoomTable(string strEntretenimientohID, string strYear)
        {
            WhereClip wcp = new WhereClip();
            if (!string.IsNullOrEmpty(strYear))
            {
                wcp = wcp.And(TB_Exam_ExamRoom._.ExamYear == strYear);
            }
            if (!string.IsNullOrEmpty(strEntretenimientohID))
            {
                wcp = wcp.And(TB_Exam_ExamRoom._.EntretenimientohID == strEntretenimientohID);
            }
            return dal.GetTable<TB_Exam_ExamRoom>(wcp);
        }

        public TB_Exam_ExamRoom GetExamRoomModel(string strExamRoomNO)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Exam_ExamRoom._.ExamRoomNO == strExamRoomNO);
            return dal.GetModel<TB_Exam_ExamRoom>(wcp);
        }

        public JsonMessage SaveExamRoom(string strJson)
        {
            JsonMessage json = new JsonMessage();
            try
            {
                TB_Exam_ExamRoom model = JsonHelper.JsonDeserialize<TB_Exam_ExamRoom>(strJson);
                if (model.IsNewModel)
                {
                    model.ExamRoomNO = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                    if (dal.GetModel<TB_Exam_ExamRoom>(TB_Exam_ExamRoom._.ExamRoomNO == model.ExamRoomNO) != null)
                    {
                        json = new JsonMessage();
                        json.State = "false";
                        json.Msg = "保存失败:考场编号已经存在,请重新输入考场编号!";
                        return json;
                    }
                }
                dal.Save<TB_Exam_ExamRoom>(model);
                json.State = "true";
                json.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                json = new JsonMessage();
                json.State = "false";
                json.Msg = "操作失败:" + ex.Message;
            }
            return json;
        }

        public JsonMessage SaveExamRoomMacMapping(string strJson)
        {
            JsonMessage json = new JsonMessage();
            try
            {
                TB_Exam_ExamRoomMacMapping model = strJson.ToList<TB_Exam_ExamRoomMacMapping>();
                dal.Save<TB_Exam_ExamRoomMacMapping>(model);
                json.State = "true";
                json.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                json.State = "false";
                json.Msg = "操作失败:" + ex.Message;
            }
            return json;
        }

        public JsonMessage SaveExamRoomMacMappingList(string strJson)
        {
            JsonMessage json = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                List<TB_Exam_ExamRoomMacMapping> list = strJson.ToList<List<TB_Exam_ExamRoomMacMapping>>();
                foreach (TB_Exam_ExamRoomMacMapping model in list)
                {
                    dal.Save<TB_Exam_ExamRoomMacMapping>(model, trans);
                }
                trans.Commit();
                json.State = "true";
                json.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                json.State = "false";
                json.Msg = "操作失败:" + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return json;
        }

        public JsonMessage DeleteExamRoomMacMapping(string strExamRoomNO, string strMac, string strYear)
        {
            JsonMessage json = new JsonMessage();
            try
            {
                dal.Delete<TB_Exam_ExamRoomMacMapping>(TB_Exam_ExamRoomMacMapping._.ExamRoomNO == strExamRoomNO
                    && TB_Exam_ExamRoomMacMapping._.MacNo == strMac
                    && TB_Exam_ExamRoomMacMapping._.ExamYear == strYear);
                json.State = "true";
                json.Msg = "操作成功";
            }
            catch (Exception ex)
            {
                json.State = "false";
                json.Msg = "操作失败:" + ex.Message;
            }
            return json;
        }
        #endregion

        #region 评分方式
        public DataTable GetExamScoreTypeTable(string strYear)
        {
            WhereClip wcp = new WhereClip();
            if (strYear.Length > 0)
            {
                wcp = wcp.And(TB_Sys_ExamScoreType._.ExamYear == strYear);
            }
            return dal.GetTable<TB_Sys_ExamScoreType>(wcp);
        }

        public TB_Sys_ExamScoreType GetExamScoreTypeModel(string strExamScoreTypeID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_ExamScoreType._.ExamScoreTypeID == strExamScoreTypeID);
            return dal.GetModel<TB_Sys_ExamScoreType>(wcp);
        }

        public JsonMessage SaveExamScoreType(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_ExamScoreType model = strJson.ToList<TB_Sys_ExamScoreType>();
                if (model.IsNewModel)
                {
                    model.ExamScoreTypeNO = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                }
                dal.Save<TB_Sys_ExamScoreType>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage DeleteExamScoreType(string strExamScoreTypeID)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Sys_ExamScoreType>(TB_Sys_ExamScoreType._.ExamScoreTypeID == strExamScoreTypeID);
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }

        public DataTable GetExamScoreTypeTable_Detail(string strExamScoreTypeID)
        {
            WhereClip wcp = new WhereClip();
            if (strExamScoreTypeID.Length > 0)
            {
                wcp = wcp.And(TB_Sys_ExamScoreTypeItem._.ExamScoreTypeID == strExamScoreTypeID);
            }
            return dal.GetTable<TB_Sys_ExamScoreTypeItem>(wcp);
        }

        public TB_Sys_ExamScoreTypeItem GetExamScoreTypeModel_Detail(string strTypeItemID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_ExamScoreTypeItem._.TypeItemID == strTypeItemID);
            return dal.GetModel<TB_Sys_ExamScoreTypeItem>(wcp);
        }

        public JsonMessage SaveExamScoreType_Detail(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_ExamScoreTypeItem model = JsonHelper.JsonDeserialize<TB_Sys_ExamScoreTypeItem>(strJson);
                if (model.IsNewModel)
                {
                    model.SpecialityLevelTypeItemNO = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                }
                dal.Save<TB_Sys_ExamScoreTypeItem>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage DeleteExamScoreType_Detail(string strTypeItemID)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Sys_ExamScoreTypeItem>(TB_Sys_ExamScoreTypeItem._.TypeItemID == strTypeItemID);
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }
        #endregion

        #region 考试方式
        public DataTable GetExamTypeTable(string strJson)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Dic_ExamType._.IsActive == "1");
            return dal.GetTable<TB_Dic_ExamType>(wcp);
        }

        public TB_Dic_ExamType GetExamTypeModel(string strDicNO)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Dic_ExamType._.DicNO == strDicNO);
            return dal.GetModel<TB_Dic_ExamType>(wcp);
        }

        public JsonMessage SaveExamType(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Dic_ExamType model = strJson.ToList<TB_Dic_ExamType>();
                if (model.IsNewModel)
                {
                    model.DicNO = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                }
                dal.Save(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage DeleteExamType(string strDicNO)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Dic_ExamType>(TB_Dic_ExamType._.DicNO == strDicNO);
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }

        #endregion

        #region  专业、级别、考试方式 关联
        public DataTable GetSpecialityLevelExamTypeMappingNameTable(string SpecialityKindsNO, string ExamLevel, string ExamYear)
        {
            WhereClip wcp = new WhereClip();
            if (ExamYear.Length > 0)
            {
                wcp = wcp.And(TB_Sys_SpecialityLevelExamTypeMapping._.ExamYear == ExamYear);
            }
            if (ExamLevel.Length > 0)
            {
                wcp = wcp.And(TB_Sys_SpecialityLevelExamTypeMapping._.ExamLevel == ExamLevel);
            }
            if (SpecialityKindsNO.Length > 0)
            {
                wcp = wcp.And(TB_Sys_SpecialityLevelExamTypeMapping._.SpecialityKindsNO == SpecialityKindsNO);
            }
            return dal.GetSpecialityLevelExamTypeMappingNameTable(wcp);
        }

        public DataTable GetSpecialityLevelExamTypeMappingTable(string ExamYear)
        {
            WhereClip wcp = new WhereClip();
            if (ExamYear.Length > 0)
            {
                wcp = wcp.And(TB_Sys_SpecialityLevelExamTypeMapping._.ExamYear == ExamYear);
            }
            return dal.GetTable<TB_Sys_SpecialityLevelExamTypeMapping>(wcp, new OrderByClip(TB_Sys_SpecialityLevelExamTypeMapping._.ExamTypeNo, OrderByOperater.ASC));
        }

        public TB_Sys_SpecialityLevelExamTypeMapping GetSpecialityLevelExamTypeMappingModel(string strSpecialityLevelMappingID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_SpecialityLevelExamTypeMapping._.SpecialityLevelMappingID == strSpecialityLevelMappingID);
            return dal.GetModel<TB_Sys_SpecialityLevelExamTypeMapping>(wcp);
        }

        public JsonMessage SaveSpecialityLevelExamTypeMapping(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_SpecialityLevelExamTypeMapping model = strJson.ToList<TB_Sys_SpecialityLevelExamTypeMapping>();
                dal.Save<TB_Sys_SpecialityLevelExamTypeMapping>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage DeleteSpecialityLevelExamTypeMapping(string strSpecialityLevelMappingID, string SpecialityKindsNO, string ExamLevel)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                if (strSpecialityLevelMappingID.Length > 0)
                {
                    dal.Delete<TB_Sys_SpecialityLevelExamTypeMapping>(TB_Sys_SpecialityLevelExamTypeMapping._.SpecialityLevelMappingID == strSpecialityLevelMappingID);
                }
                if (SpecialityKindsNO.Length > 0 && ExamLevel.Length > 0)
                {
                    dal.Delete<TB_Sys_SpecialityLevelMapping>(TB_Sys_SpecialityLevelMapping._.SpecialityKindsNO == SpecialityKindsNO && TB_Sys_SpecialityLevelMapping._.ExamLevelNO == ExamLevel);
                    dal.Delete<TB_Sys_SpecialityLevelExamTypeMapping>(TB_Sys_SpecialityLevelExamTypeMapping._.SpecialityKindsNO == SpecialityKindsNO && TB_Sys_SpecialityLevelExamTypeMapping._.ExamLevel == ExamLevel);
                }
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }


        public JsonMessage SaveSpecialityLevelMapping(string strJson)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                List<TB_Sys_SpecialityLevelMapping> list = strJson.ToList<List<TB_Sys_SpecialityLevelMapping>>();
                if (list != null && list.Count > 0)
                {
                    dal.Delete<TB_Sys_SpecialityLevelMapping>(TB_Sys_SpecialityLevelMapping._.SpecialityKindsNO == list[0].SpecialityKindsNO);
                    foreach (TB_Sys_SpecialityLevelMapping model in list)
                    {
                        dal.Save<TB_Sys_SpecialityLevelMapping>(model, trans);
                    }
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public DataTable GetSpecialityLevelMapping(string strSpecialityKindsNO)
        {
            WhereClip wcp = new WhereClip(); ;
            if (strSpecialityKindsNO.Length > 0)
            {
                wcp = wcp.And(TB_Sys_SpecialityLevelMapping._.SpecialityKindsNO == strSpecialityKindsNO);
            }
            else
            {
                wcp = wcp.And(TB_Sys_SpecialityLevelMapping._.SpecialityKindsNO == strSpecialityKindsNO);
            }
            return dal.GetTable<TB_Sys_SpecialityLevelMapping>(wcp, new OrderByClip(TB_Sys_SpecialityLevelMapping._.ExamLevelNO, OrderByOperater.ASC));
        }
        #endregion

        #region 考点专业相关
        public DataTable GetExamPlaceSpecialityKindsMappingTable(string strExamPlaceNO, string strSpecialityKindsNO)
        {
            WhereClip wcp = new WhereClip();
            if (strExamPlaceNO.Length > 0)
            {
                wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsMapping._.ExamPlaceNO == strExamPlaceNO);
            }
            if (strSpecialityKindsNO.Length > 0)
            {
                wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsMapping._.SpecialityKindsNO == strSpecialityKindsNO);
            }
            return dal.GetExamPlaceSpecialityKindsMappingTable(wcp);
        }

        public TB_Sys_ExamPlaceSpecialityKindsMapping GetExamPlaceSpecialityKindsMappingModel(string strExamPlaceSpecialityKindsMappingID)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsMapping._.ExamPlaceSpecialityKindsMappingID == strExamPlaceSpecialityKindsMappingID);
            return dal.GetModel<TB_Sys_ExamPlaceSpecialityKindsMapping>(wcp);
        }

        public JsonMessage SaveExamPlaceSpecialityKindsMapping(string strJson)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                TB_Sys_ExamPlaceSpecialityKindsMapping model = strJson.ToList<TB_Sys_ExamPlaceSpecialityKindsMapping>();
                if (model != null)
                {
                    model.ExamEndDate = model.ExamEndDate.ToSafeDateTime();
                    model.ExamStartDate = model.ExamStartDate.ToSafeDateTime();
                    model.SceneEndDate = model.SceneEndDate.ToSafeDateTime();
                    model.SceneStartDate = model.SceneStartDate.ToSafeDateTime();
                }
                if (!model.IsNewModel)
                {
                    Dictionary<Field, object> dic = new Dictionary<Field, object>();
                    dic.Add(TB_Sys_ExamPlaceSpecialityKindsMapping._.ExamEndDate, model.ExamEndDate);
                    dic.Add(TB_Sys_ExamPlaceSpecialityKindsMapping._.ExamStartDate, model.ExamStartDate);
                    dic.Add(TB_Sys_ExamPlaceSpecialityKindsMapping._.SceneEndDate, model.SceneEndDate);
                    dic.Add(TB_Sys_ExamPlaceSpecialityKindsMapping._.SceneStartDate, model.SceneStartDate);
                    dic.Add(TB_Sys_ExamPlaceSpecialityKindsMapping._.IsOpen, model.IsOpen);
                    dic.Add(TB_Sys_ExamPlaceSpecialityKindsMapping._.IsOnlineReg, model.IsOnlineReg);
                    DbHelper.GetDatabase().Update<TB_Sys_ExamPlaceSpecialityKindsMapping>(dic, TB_Sys_ExamPlaceSpecialityKindsMapping._.ExamPlaceSpecialityKindsMappingID == model.ExamPlaceSpecialityKindsMappingID);
                }
                else
                {
                    dal.Save<TB_Sys_ExamPlaceSpecialityKindsMapping>(model, trans);
                }
                if (!string.IsNullOrEmpty(model.ExamPlaceNO) && !string.IsNullOrEmpty(model.SpecialityKindsNO))
                {
                    using (DataTable dt = dal.GetTable("select * from TB_Exam_Entretenimientoh where ExamPlaceNO='" + model.ExamPlaceNO + "' and SpecialityKindsNO='" + model.SpecialityKindsNO + "'"))
                    {
                        if (dt.Rows.Count == 0)
                        {
                            dal.ExecuteNonQuery("insert into TB_Exam_Entretenimientoh select NEWID(),'" + model.ExamPlaceNO + "',SpecialityKindsNO,ExamLevel,ExamScoreTypeID,ExamYear from TB_Sys_SpecialityLevelExamTypeMapping where SpecialityKindsNO='" + model.SpecialityKindsNO + "'", trans);
                        }
                    }
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage DeleteExamPlaceSpecialityKindsMapping(string strExamPlaceSpecialityKindsMappingID)
        {
            JsonMessage message = new JsonMessage();
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsMapping._.ExamPlaceSpecialityKindsMappingID == strExamPlaceSpecialityKindsMappingID);
            TB_Sys_ExamPlaceSpecialityKindsMapping model = dal.GetModel<TB_Sys_ExamPlaceSpecialityKindsMapping>(wcp);
            if (model != null)
            {
                DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
                try
                {
                    dal.ExecuteNonQuery("delete TB_Exam_Entretenimientoh where ExamPlaceNO='" + model.ExamPlaceNO + "' and SpecialityKindsNO='" + model.SpecialityKindsNO + "'", trans);
                    dal.Delete<TB_Sys_ExamPlaceSpecialityKindsMapping>(TB_Sys_ExamPlaceSpecialityKindsMapping._.ExamPlaceSpecialityKindsMappingID == strExamPlaceSpecialityKindsMappingID, trans);
                    message.State = "true";
                    message.Msg = "删除成功!";
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    message.State = "false";
                    message.Msg = "删除失败:" + ex.Message;
                    throw ex;
                }
                finally
                {
                    trans.Close();
                }
            }
            else
            {
                message.State = "false";
                message.Msg = "删除失败:没有获取到需要删除的基本信息";
            }
            return message;
        }

        public DataTable GetExamPlaceSpecialityKindsGroupTable(string strExamPlaceSpecialityKindsMappingID, string strExamPlaceNO,
            string strSpecialityKindsNO, string strExamLevel)
        {
            WhereClip wcp = new WhereClip();
            if (strExamPlaceSpecialityKindsMappingID.Length > 0)
            {
                wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.ExamPlaceSpecialityKindsMappingID == strExamPlaceSpecialityKindsMappingID);
            }
            if (!string.IsNullOrEmpty(strExamPlaceNO))
            {
                wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.ExamPlaceNO == strExamPlaceNO);
            }
            if (!string.IsNullOrEmpty(strExamLevel))
            {
                wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.ExamLevel == strExamLevel);
            }
            if (!string.IsNullOrEmpty(strSpecialityKindsNO))
            {
                wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.SpecialityKindsNO.SelectIn(strSpecialityKindsNO.Split(',')));
            }
            return dal.GetExamPlaceSpecialityKindsGroupMappingTable(wcp);
        }

        public TB_Sys_ExamPlaceSpecialityKindsGroupMapping GetExamPlaceSpecialityKindsGroupMappingModel(string strExamPlaceSpecialityKindsMappingID, string strGroupNo)
        {
            WhereClip wcp = new WhereClip();
            wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.GroupNo == strGroupNo);
            if (!string.IsNullOrEmpty(strExamPlaceSpecialityKindsMappingID))
            {
                wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.ExamPlaceSpecialityKindsMappingID == strExamPlaceSpecialityKindsMappingID);
            }
            return dal.GetModel<TB_Sys_ExamPlaceSpecialityKindsGroupMapping>(wcp);
        }

        public JsonMessage SaveExamPlaceSpecialityKindsGroupMapping(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Sys_ExamPlaceSpecialityKindsGroupMapping model = strJson.ToList<TB_Sys_ExamPlaceSpecialityKindsGroupMapping>();
                if (model.IsNewModel)
                {
                    model.GroupNo = ServiceHelper.CreateCommService().CreateTableAppNo(model.GetTableName(), model.ExamYear);
                    WhereClip wcp = new WhereClip();
                    wcp = wcp.And(TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.GroupNo == model.GroupNo);
                    if (dal.GetModel<TB_Sys_ExamPlaceSpecialityKindsGroupMapping>(wcp) != null)
                    {
                        message.State = "false";
                        message.Msg = "该分组编号已经存在,请重新输入编号!";
                        return message;
                    }
                }
                dal.Save<TB_Sys_ExamPlaceSpecialityKindsGroupMapping>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存失败," + ex.Message;
            }
            return message;
        }

        public JsonMessage DeleteExamPlaceSpecialityKindsGroupMapping(string strExamPlaceSpecialityKindsMappingID, string strGroupNo)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                dal.Delete<TB_Sys_ExamPlaceSpecialityKindsGroupMapping>(
                    TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.ExamPlaceSpecialityKindsMappingID == strExamPlaceSpecialityKindsMappingID &&
                    TB_Sys_ExamPlaceSpecialityKindsGroupMapping._.GroupNo == strGroupNo
                    );
                message.State = "true";
                message.Msg = "删除成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "删除失败:" + ex.Message;
            }
            return message;
        }
        #endregion

        #region Pad相关设置
        public DataTable GetDicPadShowFiledAllTable(string strIsWhere)
        {
            if (strIsWhere == "0")
            {
                return dal.GetTable("select * from TB_Dic_PadFiledAll where IsActive='1' and DicNO not in (select DicNO from TB_Dic_PadFiledShow where IsActive='1')");
            }
            else
            {
                return dal.GetTable("select * from TB_Dic_PadFiledAll where IsActive='1'");
            }
        }

        public DataTable GetDicPadShowFiledShowTable()
        {
            return dal.GetTable("select * from TB_Dic_PadFiledShow where IsActive='1' order by Sort");
        }

        public JsonMessage SaveDicPadFiledShow(string strJson)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                List<TB_Dic_PadFiledShow> modelList = strJson.ToList<List<TB_Dic_PadFiledShow>>();
                int maxSort = DbHelper.GetDatabase().FromSql("select ISNULL(MAX(sort),0) from TB_Dic_PadFiledShow").ToScalar<int>();
                for (int i = 0; i < modelList.Count; i++)
                {
                    TB_Dic_PadFiledShow model = modelList[i];
                    model.Sort = maxSort + 1 + i;
                    dal.Save<TB_Dic_PadFiledShow>(model, trans);
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败!";
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage DeleteDicPadFiledShow(string strJson)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                List<string> modelList = strJson.ToList<List<string>>();
                foreach (string strDicNo in modelList)
                {
                    dal.ExecuteNonQuery("delete TB_Dic_PadFiledShow where DicNO='" + strDicNo + "'", trans);
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "移出成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "移出失败!";
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage SortDicPadFiledShow(string strJson)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                Dictionary<string, string> modelList = strJson.ToList<Dictionary<string, string>>();
                foreach (KeyValuePair<string, string> key in modelList)
                {
                    dal.ExecuteNonQuery("Update TB_Dic_PadFiledShow set Sort='" + key.Value + "' where DicNO='" + key.Key + "'", trans);
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "移动成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "移动失败:" + ex.Message;
                throw ex;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public JsonMessage SavePadExamScorePageSetting(string strJson)
        {
            JsonMessage message = new JsonMessage();
            try
            {
                TB_Dic_PadExamScorePageSetting model = strJson.ToList<TB_Dic_PadExamScorePageSetting>();
                dal.Save<TB_Dic_PadExamScorePageSetting>(model);
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                message.State = "false";
                message.Msg = "保存成功:" + ex.Message;
            }
            return message;
        }

        public JsonMessage SavePadExamScorePageSettingDetail(string strJson)
        {
            JsonMessage message = new JsonMessage();
            DbTrans trans = DbHelper.GetDatabase().BeginTransaction();
            try
            {
                List<TB_Dic_PadExamScorePageSetting_Detail> modelList = strJson.ToList<List<TB_Dic_PadExamScorePageSetting_Detail>>();
                if (modelList != null)
                {
                    if (modelList.Count > 0)
                    {
                        dal.ExecuteNonQuery("delete TB_Dic_PadExamScorePageSetting_Detail where PadExamScorePageSettingID='" + modelList[0].PadExamScorePageSettingID + "'", trans);
                    }
                    foreach (TB_Dic_PadExamScorePageSetting_Detail model in modelList)
                    {
                        dal.Save<TB_Dic_PadExamScorePageSetting_Detail>(model, trans);
                    }
                }
                trans.Commit();
                message.State = "true";
                message.Msg = "保存成功!";
            }
            catch (Exception ex)
            {
                trans.Rollback();
                message.State = "false";
                message.Msg = "保存失败:" + ex.Message;
            }
            finally
            {
                trans.Close();
            }
            return message;
        }

        public TB_Dic_PadExamScorePageSetting GetPadExamScorePageSettingModel(string strPadExamScorePageSettingType)
        {
            return dal.GetModel<TB_Dic_PadExamScorePageSetting>(TB_Dic_PadExamScorePageSetting._.PadExamScorePageSettingType == strPadExamScorePageSettingType);
        }

        public List<TB_Dic_PadExamScorePageSetting_Detail> GetPadExamScorePageSettingDetailList(string strPadExamScorePageSettingID)
        {
            return dal.GetList<TB_Dic_PadExamScorePageSetting_Detail>(TB_Dic_PadExamScorePageSetting_Detail._.PadExamScorePageSettingID == strPadExamScorePageSettingID,
                new OrderByClip(TB_Dic_PadExamScorePageSetting_Detail._.Sort, OrderByOperater.ASC));
        }
        #endregion
    }
}
